import Vue from 'vue'
import Vuex from 'vuex'
import storage from '../libs/Stroage.js'
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    rights:storage.get('rights'),
    user: storage.get('user'),
    token: sessionStorage.getItem('TOKEN')
  },
  getters: {
  },
  mutations: {
    saveToken(state, payload) {
      state.token = payload
      storage.save('TOKEN', payload)
    },
    saveToken(state, payload) {
      state.token = payload
      //将user对象存入storage中去
      sessionStorage.setItem('TOKEN', payload)
    },
    saveUser(state, payload) {
      state.user = payload
      storage.save('user', payload)
    },
    saverights(state, payload) {
      state.rights = payload
      storage.save('rights', payload)
    },
    
  },
  actions: {
    getLocation(store) {
      setTimeout(() => {
        let city = '石家庄'
        store.commit('saveCity', city)
      }, 2000)
    }
  },
  modules: {
  }
})